dnl	This file is an input file used by the GNU "autoconf" program to
dnl	generate the file "configure", which is run during Tcl installation
dnl	to configure the system for the local environment.
AC_INIT(stInternal.h)
# @(#) configure.in 1.5 95/09/26 11:26:11

#--------------------------------------------------------------------
AC_PREFIX_PROGRAM(tclsh)
AC_ARG_WITH(gcc, , CC=gcc)
AC_ARG_WITH(acc, , CC=acc)
AC_ARG_WITH(lcc, , CC=lcc)
AC_ARG_WITH(cc, , CC=cc)

ORIGCLFAGS="$CFLAGS"
AC_PROG_CC
AC_C_CROSS
CFLAGS="$ORIGCFLAGS"
AC_PROG_RANLIB

AC_PROG_INSTALL

AC_SUBST(CC)

#--------------------------------------------------------------------
#	Supply substitutes for missing POSIX library procedures, or
#	set flags so Tcl uses alternate procedures.
#--------------------------------------------------------------------

AC_REPLACE_FUNCS(strtol)
AC_CHECK_FUNC(strerror, , AC_DEFINE(NO_STRERROR))

#--------------------------------------------------------------------
#	On a few very rare systems, all of the libm.a stuff is
#	already in libc.a.  Set compiler flags accordingly.
#	Also, Linux requires the "ieee" library for math to work
#	right (and it must appear before "-lm").
#--------------------------------------------------------------------

AC_CHECK_FUNC(sin, MATH_LIBS="", MATH_LIBS="-lm")
AC_SUBST(MATH_LIBS)
AC_CHECK_LIB(ieee, main, [MATH_LIBS="-lieee $MATH_LIBS"])

#--------------------------------------------------------------------
#	Supply substitutes for missing POSIX header files.  Special
#	notes:
#	    - Sprite's dirent.h exists but is bogus.
#	    - stdlib.h doesn't define strtol, strtoul, or
#	      strtod insome versions of SunOS
#	    - some versions of string.h don't declare procedures such
#	      as strstr
#--------------------------------------------------------------------

AC_HAVE_HEADERS(unistd.h)
AC_CHECK_HEADER(errno.h, , AC_DEFINE(NO_ERRNO_H))
AC_CHECK_HEADER(limits.h, , AC_DEFINE(NO_LIMITS_H))
AC_CHECK_HEADER(stdlib.h, tcl_ok=1, tcl_ok=0)
AC_EGREP_HEADER(strtol, stdlib.h, , tcl_ok=0)
AC_EGREP_HEADER(strtoul, stdlib.h, , tcl_ok=0)
AC_EGREP_HEADER(strtod, stdlib.h, , tcl_ok=0)
if test $tcl_ok = 0; then
    AC_DEFINE(NO_STDLIB_H)
fi
AC_CHECK_HEADER(string.h, tcl_ok=1, tcl_ok=0)
AC_EGREP_HEADER(strerror, string.h, , tcl_ok=0)
if test $tcl_ok = 0; then
    AC_DEFINE(NO_STRING_H)
fi

#--------------------------------------------------------------------
#	Check for strtoul function.  This is tricky because under some
#	versions of AIX strtoul returns an incorrect terminator
#	pointer for the string "0".
#--------------------------------------------------------------------

AC_CHECK_FUNC(strtoul, tcl_ok=1, tcl_ok=0)
AC_TRY_RUN([
extern int strtoul();
int main()
{
    char *string = "0";
    char *term;
    int value;
    value = strtoul(string, &term, 0);
    if ((value != 0) || (term != (string+1))) {
        exit(1);
    }
    exit(0);
}], , tcl_ok=0, dummy=1)
if test $tcl_ok = 0; then
    test -n "$verbose" && echo "	Adding strtoul.o."
    LIBOBJS="$LIBOBJS strtoul.o"
fi

#--------------------------------------------------------------------
#	Check for the strtod function.  This is tricky because in some
#	versions of Linux strtod mis-parses strings starting with "+".
#--------------------------------------------------------------------

AC_CHECK_FUNC(strtod, tcl_ok=1, tcl_ok=0)
AC_TRY_RUN([
extern double strtod();
int main()
{
    char *string = " +69";
    char *term;
    double value;
    value = strtod(string, &term);
    if ((value != 69) || (term != (string+4))) {
	exit(1);
    }
    exit(0);
}], , tcl_ok=0, dummy=1)
if test $tcl_ok = 0; then
    test -n "$verbose" && echo "	Adding strtod.o."
    LIBOBJS="$LIBOBJS strtod.o"
fi

#--------------------------------------------------------------------
#	Under Solaris 2.4, strtod returns the wrong value for the
#	terminating character under some conditions.  Check for this
#	and if the problem exists use a substitute procedure
#	"fixstrtod" that corrects the error.
#--------------------------------------------------------------------

AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)
if test "$tcl_strtod" = 1; then
    AC_MSG_CHECKING([for Solaris strtod bug])
    AC_TRY_RUN([
	extern double strtod();
	int main()
	{
	    char *string = "NaN";
	    char *term;
	    strtod(string, &term);
	    if ((term != string) && (term[-1] == 0)) {
		exit(1);
	    }
	    exit(0);
	}], AC_MSG_RESULT(ok), [
	    AC_MSG_RESULT(buggy)
	    LIBOBJS="$LIBOBJS fixstrtod.o"
	    AC_DEFINE(strtod, fixstrtod)
	], dummy=1)
fi

#--------------------------------------------------------------------
#	Check for various typedefs and provide substitutes if
#	they don't exist.
#--------------------------------------------------------------------

AC_TYPE_MODE_T
AC_TYPE_SIZE_T

#--------------------------------------------------------------------
#	Check to see whether the system supports the matherr function
#	and its associated type "struct exception".
#--------------------------------------------------------------------

AC_MSG_CHECKING([matherr support])
AC_TRY_COMPILE([#include <math.h>], [
struct exception x;
x.type = DOMAIN;
x.type = SING;
], tcl_ok=yes, tcl_ok=no)
AC_MSG_RESULT($tcl_ok)
if test $tcl_ok = yes; then
    AC_DEFINE(NEED_MATHERR)
fi

#--------------------------------------------------------------------
#	See if we can find the Tcl binary
#--------------------------------------------------------------------

AC_CHECK_PROG(TCLSH, tclsh, tclsh )
AC_CHECK_PROG(TCLSH, tcl, tcl )
AC_SUBST(TCLSH)

if test -z "$TCLSH" ; then
    AC_MSG_ERROR([cannot find installed Tcl binary])
fi

AC_MSG_CHECKING([for Tcl version])
changequote(, )
TCLVERSION=`echo "puts stdout [info tclversion]" | $TCLSH`
changequote([, ])
AC_SUBST(TCLVERSION)
AC_MSG_RESULT([$TCLVERSION])

TCLLIBRARY="-ltcl$TCLVERSION"
if test "x$TCLLIBRARY" = "x" ; then
    AC_CHECK_LIB(tcl, main, [TCLLIBRARY="-ltcl$TCLVERSION"], , [-lm])
fi
if test "x$TCLLIBRARY" = "x" ; then
    AC_MSG_ERROR([cannot find installed Tcl library])
fi
AC_SUBST(TCLLIBRARY)



#--------------------------------------------------------------------
#	The statements below define a collection of symbols related to
#	dynamic loading and shared libraries.  See Makefile.in for a
#	description of each of the symbols.
#--------------------------------------------------------------------

AC_MSG_CHECKING([system version])
system=`uname -s`-`uname -r`
if test "$status" = 1 ; then
    AC_MSG_RESULT([unknown (can't find uname command)])
    system=unknown
else
    # Special check for weird MP-RAS system
    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
	system=MP-RAS-`awk '{print $3}' /etc/.relid`
    fi
    AC_MSG_RESULT($system)
fi
AC_ARG_ENABLE(load, [  --disable-load          disallow dynamic loading and "load" command],
    [tcl_ok=$enableval], [tcl_ok=yes])
if test "$tcl_ok" = "no"; then
    system=unknown
fi

CCOPTIONS="-O"

case $system in
    AIX-*)
	# Warning:  the AIX definitions have never been tested and I'm
	# pretty sure that they don't work as is.  This code is just
	# a starting point for a real implementation.
	# SHLIB_CFLAGS=""
	# SHLIB_LD="/bin/ld -e _nostart -berok  -bM:SRE -bE:lib$(LIBNAME).exp -H512 -T512"
	# SHLIB_SUFFIX=".so"
	# DL_LIBS=""
	# LD_FLAGS=""
	echo "Dynamic loading isn't available yet under AIX."
	echo "Want to volunteer?"
	;;
    HP-UX-*.08.*|HP-UX-*.09.*)
	if test "$CC" = "cc" ; then
	    CCOPTIONS="-Aa -O"
	fi
	SHLIB_CFLAGS="+z"
	SHLIB_LD="ld -b"
	SHLIB_SUFFIX=".sl"
	DL_LIBS="-ldld"
	LD_FLAGS="-Wl,-E"
	;;
    IRIX-5.*)
	SHLIB_CFLAGS=""
	SHLIB_LD="ld -shared -rdata_shared"
	SHLIB_SUFFIX=".so"
	DL_LIBS=""
	LD_FLAGS=""
	;;
    Linux*)
	SHLIB_CFLAGS="-fpic"
	SHLIB_LD="ld -shared"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldld"
	LD_FLAGS=""
	;;
    OSF-1.*)
	SHLIB_CFLAGS="-fpic"
	SHLIB_LD='ld -shared -expect_unresolved "*"'
	SHLIB_SUFFIX=".so"
	DL_LIBS=""
	LD_FLAGS=""
	;;
    OSF1-V*)
	SHLIB_CFLAGS=""
	SHLIB_LD='ld -shared -expect_unresolved "*"'
	SHLIB_SUFFIX=".so"
	DL_LIBS=""
	LD_FLAGS=""
	;;
    SunOS-4*)
	SHLIB_CFLAGS="-pic"
	SHLIB_LD="ld -assert pure-text"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	;;
    SunOS-5*)
	SHLIB_CFLAGS="-K pic"
	SHLIB_LD="/usr/ccs/bin/ld -G -z text"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	;;
    NetBSD-*|FreeBSD-*)
	# Not available on all versions:  check for include file.
	if test -e /usr/include/dlfcn.h; then
	    SHLIB_CFLAGS="-fpic"
	    SHLIB_LD="ld -Bshareable"
	    SHLIB_SUFFIX=".so"
	    DL_LIBS=""
	    LD_FLAGS=""
	fi
	;;
    SCO_SV-3.2*)
	# Note, dlopen is available only on SCO 3.2.5 and greater...
	SHLIB_CFLAGS="-Kpic -belf"
	SHLIB_LD="ld -G -z text"
	SHLIB_SUFFIX=".so"
	DL_LIBS=""
	LD_FLAGS="-belf -Wl,-Bexport"
	;;
    MP-RAS-02*)
	if test "$CC" = "cc" ; then
	    CCOPTIONS="-Xa -O"
	fi
	SHLIB_CFLAGS="-K pic"
	SHLIB_LD="cc -G"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldl"
	LD_FLAGS=""
	;;
    MP-RAS-*)
	if test "$CC" = "cc" ; then
	    CCOPTIONS="-Xa -O"
	fi
	SHLIB_CFLAGS="-K pic"
	SHLIB_LD="cc -G"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldl"
	LD_FLAGS="-Wl,-Bexport"
	;;
    UNIX_SV*)
	SHLIB_CFLAGS="-K pic"
	SHLIB_LD="cc -G"
	SHLIB_SUFFIX=".so"
	DL_LIBS="-ldl"
	LD_FLAGS="-Wl,-Bexport"
	;;
esac

if test "x$SHLIB_SUFFIX" != "x" ; then
    BUILD_DLTEST="loadTests"
    LIB_SUFFIX=$SHLIB_SUFFIX
else
    echo "Can't figure out how to do dynamic loading or shared libraries"
    echo "on this system."
    SHLIB_CFLAGS=""
    SHLIB_LD=""
    SHLIB_SUFFIX=""
    DL_LIBS=""
    LD_FLAGS=""
    BUILD_DLTEST=""
    LIB_SUFFIX=.a
fi

if test "$CC" = "gcc" -a "x$SHLIB_SUFFIX" != "x" ; then
    SHLIB_CFLAGS="-fpic"
fi

AC_SUBST(CCOPTIONS)
AC_SUBST(LIB_SUFFIX)
AC_SUBST(SHLIB_CFLAGS)
AC_SUBST(SHLIB_LD)
AC_SUBST(SHLIB_SUFFIX)
AC_SUBST(DL_LIBS)
AC_SUBST(LD_FLAGS)
AC_SUBST(BUILD_DLTEST)




AC_OUTPUT(Makefile)
